<?php


namespace Cblood\Sword\Operation;


class OrganizeUpdate extends OrganizeSqlBasic
{
    /**
     * 创建update语句
     * @param array $update
     * @return string
     */
    public function create(array $update)
    {
        $updateArray = [];
        foreach ($update as $name => $value) {
            $updateArray[] = $name . "='" . $value . "'";
        }
        $updateSql = implode(',', $updateArray);

        $result = 'UPDATE ' . $this->getTable() . ' SET ' . $updateSql;
        $where = $this->createWhereConditions();
        !empty($where) && $result = $result . ' WHERE ' . $where;
        return $result;
    }
}